package transforms;
import org.objectweb.asm.tree.FieldNode;

import com.rshacking.rhf.files.ClassContainer;
import com.rshacking.rhf.updater.Transform;
import com.rshacking.rhf.updater.hooks.ClassHook;
import com.rshacking.rhf.updater.hooks.HooksList;

public class ObjectDataTransform extends Transform {

	@Override
	public boolean canActivate(HooksList hooks, ClassContainer cc) {
		for (FieldNode fn : cc.getASM().fields) {
			if (fn.desc.startsWith("[[[L")) {
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean execute(HooksList hooks, ClassContainer cc) {
		ClassHook c = null;
		if (hooks.contains("Client"))
			c = hooks.get("Client");
		else
			c = hooks.add("Client", "client");
		
		for (FieldNode fn : cc.getASM().fields) {
			if (fn.desc.startsWith("[[[L")) {
				c.add(cc.getASM(), "objectData", fn);
				return true;
			}
		}
		return false;
	}
}